{%- set options = options ?? [] %}
{%- set values = values ?? [] -%}

{%- set showAllOption = showAllOption ?? false %}
{%- if showAllOption %}
    {%- set allLabel = allLabel ?? "All"|t('app') %}
    {%- set allValue = allValue ?? '*' %}
    {%- set allChecked = (values == allValue) %}
{%- endif %}

<fieldset class="checkbox-select{% if class ?? false %} {{ class }}{% endif %}"
        {%- if block('attr') is defined %} {{ block('attr') }}{% endif %}>
    {%- if showAllOption %}
        <div>
            {% include "_includes/forms/checkbox" with {
                id: id ?? null,
                class: 'all',
                label: raw("<b>#{allLabel}</b>"),
                name: name ?? null,
                value: allValue,
                checked: allChecked,
                autofocus: (autofocus ?? false) and not craft.app.request.isMobileBrowser(true),
            } only %}
        </div>
    {%- endif %}
    {%- for key, option in options %}
        {%- if option is not iterable %}
            {%- set option = {label: option, value: key} %}
        {%- endif %}
        {% if not showAllOption or option.value is not defined or option.value != allValue %}
            <div>
                {% include "_includes/forms/checkbox" with {
                    name: (name ?? false) ? "#{name}[]" : null,
                    checked: ((showAllOption and allChecked) or (option.value is defined and option.value in values)),
                    disabled: (showAllOption and allChecked)
                }|merge(option) only %}
            </div>
        {% endif %}
    {% endfor %}
</fieldset>
